package many.to.many;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

//@Entity
//@Table(uniqueConstraints = {
//		@UniqueConstraint(columnNames = "stockName"),
//		@UniqueConstraint(columnNames = "stockCode") })
public class Stock implements java.io.Serializable {
 
	private static final long serialVersionUID = -2212166428876081583L;
	
	private Integer stockId;
	private String stockCode;
	private String stockName;
	private Set<Category> categories = new HashSet<Category>(0);
 
	public Stock() {
	}
 
	public Stock(String stockCode, String stockName) {
		this.stockCode = stockCode;
		this.stockName = stockName;
	}
 
	public Stock(String stockCode, String stockName, Set<Category> categories) {
		this.stockCode = stockCode;
		this.stockName = stockName;
		this.categories = categories;
	}
 
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Integer getStockId() {
		return this.stockId;
	}
 
	public void setStockId(Integer stockId) {
		this.stockId = stockId;
	}
 
	public String getStockCode() {
		return this.stockCode;
	}
 
	public void setStockCode(String stockCode) {
		this.stockCode = stockCode;
	}
 
	public String getStockName() {
		return this.stockName;
	}
 
	public void setStockName(String stockName) {
		this.stockName = stockName;
	}
 
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "stock_category", joinColumns = { 
			@JoinColumn(name = "stockId_2") }, 
			inverseJoinColumns = { @JoinColumn(name = "categoryId_2", 
					nullable = false, updatable = false) })
	public Set<Category> getCategories() {
		return this.categories;
	}
 
	public void setCategories(Set<Category> categories) {
		this.categories = categories;
	}
 
}

